package com.purple.tasks;

import com.pink.RobotEx;
import com.purple.CPSignal;
import com.purple.ColorPoint;
import com.purple.LogAppender;

import java.awt.*;
import java.util.concurrent.SynchronousQueue;

public class RightNowTask implements Runnable {
    private ColorPoint colorPoint;
    private RobotEx robot;
    private LogAppender appender;
    private SynchronousQueue<CPSignal> feedbackQueue;

    public RightNowTask(ColorPoint colorPoint, RobotEx robot,
                        LogAppender appender,
                        SynchronousQueue<CPSignal> feedbackQueue) {

        this.colorPoint = colorPoint;
        this.robot = robot;
        this.appender = appender;
        this.feedbackQueue = feedbackQueue;
    }

    @Override
    public void run() {
        Color c = robot.getPixelColor(colorPoint.getX(), colorPoint.getY());
        if (c.equals(new Color(colorPoint.getR(),colorPoint.getG(),colorPoint.getB()))) {
            try {
                feedbackQueue.put(new CPSignal(true));
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }else {
            try {
                feedbackQueue.put(new CPSignal(false));
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
